<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Home</title>
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" />
    <script src="js/jquery.min.js"></script>
    <script src="js/layer-v3.1.1/layer/layer.js"></script>
    <script src="js/demo.js"></script>
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <script src="assets/js/lib/bootstrap.min.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
    <script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
</head>
<script src="assets/js/lib/jquery.min.js"></script>
<script type="text/javascript">
    var classDelete = function (){
        var ID=$("#ID").val();
        $.ajax({
            type: 'POST',
            url: '<%=request.getContextPath() %>/ClassDelete?classid="'+ID+'"',
            dataType: 'json',
            data: {},
            contentType: 'application/json;charset=UTF-8',
            success: function(e) {
                if (e.status === "COMMITTED") {
                }
                window.location="<%=request.getContextPath() %>/manage/allClass.jsp";
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
            },
        });
    }
    var cancel=function(){
        layer.close(index);
        $("#deleteBox").css("display","none");
    }
    var classModify = function (){
        var classid=$.trim($("#InputClassId").val());
        var classname=$.trim($("#InputClassName").val());
        var classurl=$.trim($("#InputClassUrl").val());
        var classnum=Number($.trim($("#InputClassNum").val()));
        var classprice=$.trim($("#InputClassPrice").val());
        var classteacher=$.trim($("#InputTeacher").val());
        var classplace=Number($.trim($("#InputPlace").val()));
        $.ajax({
            type: 'POST',
            url: '<%=request.getContextPath() %>/ClassModify',
            dataType: 'json',
            data: JSON.stringify({
                classid: classid,
                classname: classname,
                classurl: classurl,
                classnum: classnum,
                classprice: classprice,
                classteacher:classteacher,
                classplace:classplace
            }),
            contentType: 'application/json;charset=UTF-8',
            success: function(e) {
                if (e.status === "COMMITTED") {
                    window.alert('已提交执行');
                }
                window.location="<%=request.getContextPath() %>/manage/allClass.jsp";
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $("#loginBox").css("display","none");
            },
        });
    }
    var classAdd = function (){
        var classname=$.trim($("#AddClassName").val());
        var classurl=$.trim($("#AddClassUrl").val());
        var classprice=$.trim($("#AddClassPrice").val());
        var classnum=Number($.trim($("#AddClassNum").val()));
        var type=Number($.trim($("#type_select").val()));
        var place_id=Number($.trim($("#place_select").val()));
        var teacher_id=$.trim($("#teacher_select").val());
        $.ajax({
            type: 'POST',
            url: '<%=request.getContextPath() %>/ClassAdd',
            dataType: 'json',
            data: JSON.stringify({
                classname: classname,
                classurl: classurl,
                classprice: classprice,
                classtype:type,
                classnum:classnum,
                classteacher:teacher_id,
                classplace:place_id
            }),
            contentType: 'application/json;charset=UTF-8',
            success: function(e) {
                if (e.status === "COMMITTED") {
                    window.alert('已提交执行');
                }
                window.location="<%=request.getContextPath() %>/manage/allClass.jsp";
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $("#addBox").css("display","none");
            },
        });
    }
    var searchclass=function (){
        var keyword=$.trim($("#key").val());
        $.ajax({
            url:"<%=request.getContextPath()%>/ShowClassByKeyword?keyword='"+keyword+"'",
            type:"GET",
            dataType:"json",
            success: function(data) {
                var item=data;
                var html = "";
                for(var i=0;i<item.length;i++){
                    var classid=item[i].class_id;
                    var classname=item[i].class_name;
                    var classprice=item[i].class_price;
                    var classnum=item[i].class_num;
                    var classurl=item[i].class_url;
                    var teachername=item[i].teacher?item[i].teacher.teacher_name:"";
                    var teacherid=item[i].teacher?item[i].teacher.teacher_id:"";
                    var placename=item[i].place?item[i].place.place_name:"";
                    var placeid=item[i].place?item[i].place.place_id:"";
                    html += '<tr><td id="classid">' + classid + '</td><td id="classname">'
                        + classname+ '</td><td id="classprice">'
                        + classprice + '</td><td id="teachername">'
                        + teachername + '</td><td id="placename">'
                        + placename + '</td><td><a href="javascript:;" id="bLogin" onclick="ShowClassText(\''+classid+'\',\''+classname+'\',,\''+classurl+'\',\''+classnum+'\',\''+classprice+'\',\''+teacherid+'\',\''+placeid+'\')">编辑</a></td><td><a href="javascript:;" id="bLogin" onclick="ShowDeleteText(\''+classid+'\')" >删除</a></td></tr>';
                }
                $("#classlist").empty();
                $("#classlist").append(html);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            },
        })
    }
    window.onload=function tryapitest(){
        $.ajax({
            url:"<%=request.getContextPath()%>/ShowClass",
            type:"GET",
            dataType:"json",
            success: function(data) {
                var item=data;
                var html = "";
                for(var i=0;i<item.length;i++){
                    var classid=item[i].class_id;
                    var classname=item[i].class_name;
                    var classprice=item[i].class_price;
                    var classnum=item[i].class_num;
                    var classurl=item[i].class_url;
                    var teachername=item[i].teacher?item[i].teacher.teacher_name:"";
                    var teacherid=item[i].teacher?item[i].teacher.teacher_id:"";
                    var placename=item[i].place?item[i].place.place_name:"";
                    var placeid=item[i].place?item[i].place.place_id:"";
                    html += '<tr><td id="classid">' + classid + '</td><td id="classname">'
                        + classname+ '</td><td id="classprice">'
                        + classprice + '</td><td id="teachername">'
                        + teachername + '</td><td id="placename">'
                        + placename + '</td><td><a href="javascript:;" id="bLogin" onclick="ShowClassText(\''+classid+'\',\''+classname+'\',\''+classurl+'\',\''+classnum+'\',\''+classprice+'\',\''+teacherid+'\',\''+placeid+'\')">编辑</a></td><td><a href="javascript:;" id="bLogin" onclick="ShowDeleteText(\''+classid+'\')" >删除</a></td></tr>';
                }
                $("#classlist").append(html);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            },
        })
    }

</script>
<body>
<div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
    <div class="nano">
        <div class="nano-content">
            <ul>
                <div class="logo"><a href="index.jsp"><span>教务管理系统后台</span></a></div>
                <li class="label">Main</li>
                <%
                    if(request.getSession().getAttribute("identity")!=null){
                        int identity=(int)request.getSession().getAttribute("identity");
                        if(identity==3){
                %>
                <li><a class="sidebar-sub-toggle"><i class="ti-home"></i>用户管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allUser.jsp">查看所有用户</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>教师管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allTeacher.jsp">查看所有教师</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-home"></i>场地管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allPlace.jsp">查看所有场地</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>班级管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allClass.jsp">查看所有班级</a></li>
                    </ul>
                </li><%
            }
            else{%>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>课程管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allCourse.jsp">查看所有课程</a></li>
                    </ul>
                </li>
                <li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>上课管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="allStudent.jsp">查看签到情况</a></li>
                    </ul>
                </li><%
                }
            }
            else{
            %>
                <a href="<%=request.getContextPath()%>/enter">请登录</a>
                <a href="<%=request.getContextPath()%>/register">免费注册</a><%
                }
            %>

            </ul>
        </div>
    </div>
</div>
<div class="header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="dropdown dib">
                    <div class="header-icon" data-toggle="dropdown">
								<span class="user-avatar"><%=request.getSession().getAttribute("userid") %>
                                    <i class="ti-angle-down f-s-10"></i>
                                </span>
                        <div class="drop-down dropdown-profile dropdown-menu dropdown-menu-right">
                            <div class="dropdown-content-body">
                                <ul>
                                    <li>
                                        <a href="#">
                                            <i class="ti-settings"></i>
                                            <span>Setting</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="<%=request.getContextPath() %>/exit">
                                            <i class="ti-power-off"></i>
                                            <span>Logout</span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<div class="content-wrap">
    <div class="main">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-8 p-r-0 title-margin-right">
                    <div class="page-header">
                        <div class="page-title">
                            <h1>Hello, <span>There are all classes.</span></h1>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div>
            <div class="card">
                <div class="card-title pr">
                    <h4>所有查找结果</h4>
                </div>
                <div>
                    <input type="text" placeholder="classid" name="key" id="key">
                    <button id="btn" type="submit" onclick="searchclass()">搜索</button>
                    <button id="add_btn" type="primary" onclick="AddClassText()">添加</button>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table student-data-table m-t-20">
                            <thead>
                            <tr>
                                <th>班级ID</th>
                                <th>班级名称</th>
                                <th>价格</th>
                                <th>教师姓名</th>
                                <th>场地名称</th>
                                <th>编辑</th>
                                <th>删除</th>
                            </tr>
                            </thead>
                            <tbody id="classlist">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="loginBox">
    <div class="login-item"><input  type="hidden" id="InputClassId"/></div>
    <div class="login-item">课程名：<input  type="text" id="InputClassName" placeholder="课程名" /></div>
    <div class="login-item">照片地址：<input  type="text" id="InputClassUrl" placeholder="照片地址"/></div>
    <div class="login-item">课程人数：<input  type="text" id="InputClassNum" placeholder="课程人数"/></div>
    <div class="login-item">课程价格：<input  type="text" id="InputClassPrice" placeholder="课程价格"/></div>
    <div class="login-item">教师：
        <select id="InputTeacher">
        </select>
    </div>
    <div class="login-item">场地：
        <select id="InputPlace">
        </select>
    </div>
    <div class="login-item"><a href="javascript:;" onclick="classModify()">修改</a></div>
</div>
<div id="addBox">
    <div class="login-item">课程名称：<input  type="text" id="AddClassName" placeholder="姓名" /></div>
    <div class="login-item">照片地址：<input  type="text" id="AddClassUrl" placeholder="照片地址"/></div>
    <div class="login-item">课程价格：<input  type="text" id="AddClassPrice" placeholder="课程价格"/></div>
    <div class="login-item">课程类型：
        <select id="type_select">
            <option value=1>篮球</option>
            <option value=2>羽毛球</option>
            <option value=3>足球</option>
            <option value=4>排球</option>
            <option value=5>乒乓球</option>
            <option value=6>网球</option>
        </select>
    </div>
    <div class="login-item">课程人数：<input  type="text" id="AddClassNum" placeholder="课程人数"/></div>
    <div class="login-item">教师：
        <select id="teacher_select">
        </select>
    </div>
    <div class="login-item">场地：
        <select id="place_select">
        </select>
    </div>
    <div class="login-item"><a href="javascript:;" onclick="classAdd()">添加</a></div>
</div>
<div id="deleteBox">
    <p>确定要删除该课程吗？</p>
    <div class="login-item"><input type="hidden" id="ID" /></div>
    <div class="delete-item div-inline"><a href="javascript:;" onclick="classDelete()">确认</a></div>
    <div class="delete-item div-inline"><a href="javascript:;" onclick="cancel()">取消</a></div>
</div>
<script src="assets/js/lib/jquery.min.js"></script>
<script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
<script src="assets/js/lib/menubar/sidebar.js"></script>
<script src="assets/js/lib/preloader/pace.min.js"></script>
<script src="assets/js/lib/bootstrap.min.js"></script>
<script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
<script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
</body>
</html>